home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 251_01 / pulldown.c < prev    next >
Text File  |  1987-10-27  |  21KB  |  820 lines

  1. /*   COPYRIGHT (C) 1986 */
  2. /*   BY JAMES L PINSON  */
  3. /*  ALL RIGHTS RESERVED */
  4.  
  5.  
  6. /* Compiled with Lattice C V2.14 */
  7. /* Computer: IBM PC JR           */
  8. /* Text editor: Sidekick         */
  9. /* Last revision 3/16/1987       */
  10.  
  11.  
  12.  
  13. #include  "stdio.h"
  14. #include  "ctype.h"
  15.  
  16. #define void int
  17.  
  18.  
  19. #define BLACK   0        /*  THESE ARE FOR COLOR CARDS */
  20. #define BLUE    1
  21. #define GREEN   2
  22. #define CYAN    3
  23. #define RED     4
  24. #define MAGENTA 5
  25. #define BROWN   6
  26. #define WHITE   7
  27. #define L_BLUE  9     /* LIGHT-BLUE FOREGROUND ONLY */
  28. #define L_GREEN 10    /* LIGHT-GREEN FOREGROUND ONLY */
  29. #define YELLOW  14
  30. #define IWHITE  15    /* INTENSE-WHITE FOREGROUND ONLY*/
  31.  
  32.  
  33.  
  34. #define UNDERLINE 1     /* THESE ARE FOR MONOCHROME CARDS */
  35. #define NORMAL    7
  36. #define HI_INTEN  15
  37. #define REVERSE   112
  38.  
  39. #define TRUE  1
  40. #define FALSE 0
  41.  
  42. unsigned int page;          /* extern decl. for functions*/
  43. unsigned int attribute;
  44. unsigned int mon_type;
  45. char wrt_meth= 'f';
  46.  
  47.  
  48.  
  49. #define  NU_MAIN 5        /* number of main menu options */
  50. #define  NU_SUB  5        /* number of sub menu options  */
  51.  
  52.  struct menu_str{        /* change this if you need more options */
  53.     char *head;
  54.     char *body[NU_SUB];
  55.     void (*fun1)();
  56.     void (*fun2)();
  57.     void (*fun3)();
  58.     void (*fun4)();
  59.     void (*fun5)();
  60.   } ;
  61.  
  62.  
  63. main(argc,argv)
  64.      int argc;
  65.      char **argv;
  66. {
  67. extern unsigned int page;
  68. extern unsigned int attribute;
  69. extern unsigned int mon_type;
  70.  
  71. char ch,ext;
  72.  
  73. int i,hi_attr,nor_attr;
  74.  
  75. int demo();
  76. int help();
  77.  
  78.  static  struct menu_str m_menu [NU_MAIN]={
  79.  
  80.      "   File   ",   /*  The first menu option       */
  81.        "   Dir      ",   /*  Menu sub options */
  82.        "   Load     ",
  83.        "   Save     ",
  84.        "   dElete   ",
  85.        "   Path     ",
  86.                 demo,   /* The functions each sub-option call */
  87.                 demo,
  88.                 demo,    /* these all call the same fake function */
  89.                 demo,
  90.                 demo,
  91.  
  92.        "   fiNd   ",           /* The second menu option */
  93.          " All-words  ",
  94.          " First-word ",
  95.          "\0",
  96.          "\0",           /* space filler for unused option names */
  97.          "\0",
  98.                 demo,
  99.                 demo,
  100.                 0,       /* unused function pointer */
  101.                 0,
  102.                 0,
  103.  
  104.        "   Configure   ",    /* The third option */
  105.          " Modem ",
  106.          " Screen ",
  107.          " Printer ",
  108.          "\0",
  109.          "\0",
  110.                 demo,
  111.                 demo,
  112.                 demo,
  113.                 0,
  114.                 0,
  115.  
  116.        "        Output       ",           /* The fourth menu option */
  117.          "  Screen  ",
  118.          "  Printer ",
  119.          "  Disk    ",
  120.          "  Modem   ",
  121.          "\0",
  122.                 demo,
  123.                 demo,
  124.                 demo,
  125.                 demo,
  126.                 0,
  127.  
  128.  
  129.            " Help ",                       /* The fifth option */
  130.            " Instant help (really works) ",
  131.            "\0",
  132.            "\0",
  133.            "\0",
  134.            "\0",
  135.                 help,
  136.                 0,
  137.                 0,
  138.                 0,
  139.                 0,
  140. };
  141.  
  142.  
  143. /* was a slow write requested? */
  144. if (tolower (*argv[1])== 's') wrt_meth = 's';
  145.  
  146. page=0;
  147.  
  148.  
  149.  mon_type =(what_mon());
  150.  
  151.   if (mon_type==1){                     /* FIND OUT IF YOU HAVE A COLOR CARD */
  152.     hi_attr=  set_color(BLACK,CYAN);    /* AND SET ATTRIBUTES ACCORDINGLY */
  153.     nor_attr= set_color(WHITE,BLACK);
  154.   }
  155.     else{
  156.      hi_attr = REVERSE;
  157.      nor_attr = NORMAL;
  158.     }
  159.  
  160.  attribute = nor_attr;
  161.  cursor(0);               /* hide cursor */
  162.  win_save('s');
  163.  cls();
  164.  
  165.  if (mon_type==1) make_help();
  166.  
  167.  make_inst();          /* SHOW INSTRUCTIONS */
  168.  
  169.  menu(m_menu,NU_MAIN,NU_SUB,hi_attr,nor_attr);
  170.  
  171.  win_save('r');        /* restore text display*/
  172.  cursor(1);            /* restore cursor      */
  173. }
  174.  
  175.  
  176. int menu (m_menu,nu_main,nu_sub,hi_attr,nor_attr)
  177. struct menu_str m_menu[];
  178. int nu_main,nu_sub,hi_attr, nor_attr;
  179.  
  180. {
  181. extern unsigned int page;
  182. extern unsigned int attribute;
  183. extern unsigned int mon_type;
  184.  
  185. int i,j,k,cur_x,cur_y,cur_opt,found,expert=1;
  186. char ch, ext, ltr;
  187.  
  188.    ch= ' ';ext=' '; cur_opt=0; found =0;
  189.  
  190. if (mon_type==1) attribute = set_color(YELLOW,BLACK);
  191. else attribute = nor_attr;
  192.  
  193. make_window(1,1,78,1,1);
  194.  
  195.  
  196.   for(;;){               /* endless loop */
  197.  
  198.         for(i=0;i<nu_main;i++){
  199.           j=0;
  200.           while(ltr = m_menu[i].head[j++]){
  201.             if ( ch==ltr && ch != ' '){
  202.              found= TRUE;
  203.              cur_opt = i;
  204.             }
  205.           }
  206.         }
  207.           if (ch==13){
  208.            found = TRUE;
  209.            expert = FALSE;
  210.           }
  211.  
  212.                    ch=' ';
  213.                    cur_x=2;cur_y=2;
  214.  
  215.  
  216.                for(i=0;i< nu_main;i++){
  217.                    if(i == cur_opt) attribute= hi_attr;
  218.                     else attribute= nor_attr;
  219.                      print(cur_x,cur_y,m_menu[i].head);
  220.  
  221.                  cur_x= cur_x+strlen(m_menu[i].head)+3;
  222.                 }
  223.  
  224.            if (!expert) found = TRUE;
  225.  
  226.            if (found){
  227.  
  228.              ext =(pull_down(m_menu,nu_sub,cur_opt)); /* pull-down options */
  229.              if (ext == 27) expert = TRUE;
  230.              if (ext == 'r' || ext == 'l') expert = FALSE;
  231.              if (ext=='r') cur_opt = cur_opt+1;
  232.              if (ext =='l') cur_opt = cur_opt -1;
  233.              ch= ' ';
  234.              ext= ' ';
  235.  
  236.             }
  237.  
  238.            if(!found){
  239.             ch=' ';
  240.             get_key(&ch,&ext);
  241.  
  242.             ch=toupper(ch);
  243.  
  244.           }
  245.  
  246.            if (ch==27) return;
  247.  
  248.            if (ext =='r' || ext == 'l') expert = 0;
  249.            if (ext == 'r')  cur_opt = cur_opt +1;
  250.            if (ext == 'l')  cur_opt = cur_opt -1;
  251.            if (cur_opt >= nu_main) cur_opt =0;
  252.            if (cur_opt < 0) cur_opt = nu_main-1;
  253.            ext=' ';
  254.            found=0;
  255.  
  256.   } /* end for(;;) */
  257.  
  258. }   /* end function */
  259.  
  260.  
  261.  
  262. int pull_down(m_menu,nu_sub,position)
  263. struct menu_str m_menu[];
  264. int position;
  265.  
  266. {
  267. extern unsigned int page;
  268. extern unsigned int attribute;
  269. char ch=' ',ltr;
  270. int ext=' ',hi_attr,nor_attr;
  271. int i,j,tx,ty,start,width,nu_opt,cur_opt=0, found= FALSE;
  272.  
  273. nu_opt = nu_sub;
  274.  
  275. /* nu_sub = number of possible pull-down options */
  276. /* find out how many are in use */
  277.  
  278. for(i=0;i<nu_opt;i++){
  279.   if (m_menu[position].body[i][0] == '\0'){
  280.    nu_opt = i;
  281.    break;
  282.   }
  283.  
  284. }
  285.  
  286.  
  287.   if (mon_type==1){
  288.     hi_attr=  set_color(BLACK,CYAN);
  289.     nor_attr= set_color(WHITE,BLACK);
  290.   }
  291.     else{
  292.      hi_attr = REVERSE;
  293.      nor_attr = NORMAL;
  294.     }
  295.  
  296.  attribute = nor_attr;
  297.  
  298. start=2;       /* figure where to draw pull-down box */
  299.               /* 2 is column to start 1st box */
  300.               /* add up length of menu heads */
  301.  
  302.   for(i=0; i< position; i++)  start= start+strlen(m_menu[i].head)+3;
  303.  
  304.  
  305.   width=0;      /* figure max length of window */
  306.  
  307.   for (i=0;i< nu_opt;i++){
  308.    if (strlen(m_menu[position].body[i]) > width){
  309.     width= strlen(m_menu[position].body[i]);
  310.    }
  311.   }
  312.  
  313.                          /* move box to left if          */
  314.                          /* it will spill off right side */
  315.  
  316.  if(start+width+1>80) start = 80-width-2;
  317.  
  318.  
  319.   win_save ('s');
  320.  
  321.  if (mon_type ==1) attribute = set_color (YELLOW,BLACK);
  322.  
  323.  make_window(start++,3,width,nu_opt,0); /*make a window */
  324.  attribute = nor_attr;
  325.  
  326. tx=start;ty=4;                       /* reposition for writing */
  327.  
  328.   for(;;){
  329.          for(i=0;i< nu_opt;i++){
  330.            if(i == cur_opt) attribute= hi_attr;
  331.             else attribute= nor_attr;
  332.             print(tx,ty++,m_menu[position].body[i]);
  333.          };
  334.  
  335.          attribute = nor_attr;
  336.  
  337.           if(found ) {
  338.              win_save('r');     /* remove box */
  339.  
  340.                 /* if you want more than 5 menu options */
  341.                 /* change this next switch statement    */
  342.  
  343.              switch (cur_opt){       /* call function */
  344.               case 0: (*m_menu[position].fun1)() ;break;
  345.               case 1: (*m_menu[position].fun2)() ;break;
  346.